__author__ = 'Junior Lima'
# -*- coding: utf-8 -*-
from django.contrib import admin
from Scope.admin import BaseNoticiaAdmin
from BlogJuvenis.models import Blog, NoticiaBlog

#Admin Blog
class BlogAdmin(admin.ModelAdmin):
    fieldsets = [
        ('Informações',{'fields':('ativo', ('nome','nomeColaborador'), ('email', 'imagem'), 'igreja', 'descricao')}),
    ]
    list_display = ['nome','nomeColaborador', 'email', 'igreja', 'ativo', 'cliques']

class BlogNoticiaAdmin(BaseNoticiaAdmin):
    # Salva o autor que cadastrou a notícia
    def save_model(self, request, obj, form, change):
        if getattr(obj, 'added_by', None) is None:
            obj.autor = request.user
        obj.last_modified_by = request.user
        obj.save()
    # Mostra apenas dados cadastrados pelos usuários atuais
    def queryset(self, request):
        buscauser = super(BlogNoticiaAdmin, self).queryset(request)
        if request.user.is_superuser:
            return buscauser
        return buscauser.filter(autor=request.user)
    class Media:
        js = ('/js/tiny_mce/tiny_mce.js', '/js/textareas.js')

    list_display = ['titulo', 'nomeBlog', 'datacriacao', 'publicar', 'cliques']
    list_filter = ['publicar','nomeBlog']
    search_fields = ['titulo']
    save_on_top= True


admin.site.register(Blog, BlogAdmin)
admin.site.register(NoticiaBlog, BlogNoticiaAdmin)